﻿// CheckResultListCtrl.cpp: 实现文件
//

#include "stdafx.h"
#include "zChecker.h"
#include "CheckResultListCtrl.h"


// CCheckResultListCtrl

IMPLEMENT_DYNAMIC(CCheckResultListCtrl, CListCtrl)

CCheckResultListCtrl::CCheckResultListCtrl()
{

}

CCheckResultListCtrl::~CCheckResultListCtrl()
{
}


BEGIN_MESSAGE_MAP(CCheckResultListCtrl, CListCtrl)
	ON_WM_CREATE()
	ON_WM_SIZE()
END_MESSAGE_MAP()



// CCheckResultListCtrl 消息处理程序




int CCheckResultListCtrl::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
	if (CListCtrl::OnCreate(lpCreateStruct) == -1)
		return -1;

	// TODO:  在此添加您专用的创建代码
	ModifyStyle(0, LVS_REPORT | LVS_SINGLESEL);
	SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES | LVS_EX_AUTOSIZECOLUMNS);

	InsertColumn(0, " ", LVCFMT_LEFT, 50);
	InsertColumn(1, "规则名称", LVCFMT_LEFT, 150);
	InsertColumn(2, "算子名称", LVCFMT_LEFT, 300);
	InsertColumn(3, "检查对象", LVCFMT_LEFT, 300);
	InsertColumn(4, "错误描述", LVCFMT_LEFT, 500);
	InsertColumn(5, "截图", LVCFMT_LEFT, 300);
	InsertColumn(6, "描述类型", LVCFMT_LEFT, 300);

	return 0;
}


void CCheckResultListCtrl::OnSize(UINT nType, int cx, int cy)
{
	CListCtrl::OnSize(nType, cx, cy);

	// TODO: 在此处添加消息处理程序代码
}


void CCheckResultListCtrl::Populate(ck::check::CheckResultSet* pResultSet)
{
	ck::check::CheckResult* pResult = NULL;
	int count = pResultSet->GetCount();

	DeleteAllItems();
	for (int i = 0; i < count; i++)
	{
		pResult = pResultSet->GetResult(i);
		Populate(pResult);
	}
}

void CCheckResultListCtrl::Populate(ck::check::CheckResult* pResult)
{
	ck::check::CheckResultItem* pItem = NULL;
	int nCount = pResult->GetCount();
	for (int i = 0; i < nCount; i++)
	{
		pItem = pResult->GetItem(i);
		int nItem = InsertItem(this->GetItemCount(), "");
		SetItemText(nItem, 2, pResult->GetOperator());
		SetItemText(nItem, 3, pItem->GetDatasetName());
		SetItemText(nItem, 4, pItem->GetMessage());
	}
}